package com.whm.hrmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.whm.hrmanagement.domain.dto.OaStaffQjDto;
import com.whm.hrmanagement.domain.vo.OaStaffQjVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whm.common.annotation.Log;
import com.whm.common.core.controller.BaseController;
import com.whm.common.core.domain.AjaxResult;
import com.whm.common.enums.BusinessType;
import com.whm.hrmanagement.domain.OaStaffQj;
import com.whm.hrmanagement.service.IOaStaffQjService;
import com.whm.common.utils.poi.ExcelUtil;
import com.whm.common.core.page.TableDataInfo;

import static com.whm.common.utils.PageUtils.startPage;

/**
 * 员工请假Controller
 * 
 * @author whm
 * @date 2024-02-05
 */
@RestController
@RequestMapping("/hrmanagement/qj")
public class OaStaffQjController extends BaseController
{
    @Autowired
    private IOaStaffQjService oaStaffQjService;

    /**
     * 查询员工请假列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:qj:list')")
    @GetMapping("/list")
    public TableDataInfo list( OaStaffQjVo oaStaffQjVo)
    {

        List<OaStaffQjDto> list = oaStaffQjService.selectOaStaffQjLis2(oaStaffQjVo);

        TableDataInfo tableDataInfo =  getDataTable(list);

        tableDataInfo.setTotal(oaStaffQjService.selectOaStaffQjList(null).stream().count());
        startPage();
        return tableDataInfo;
    }

    /**
     * 导出员工请假列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:qj:export')")
    @Log(title = "员工请假", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaStaffQj oaStaffQj)
    {
        List<OaStaffQj> list = oaStaffQjService.selectOaStaffQjList(oaStaffQj);
        ExcelUtil<OaStaffQj> util = new ExcelUtil<OaStaffQj>(OaStaffQj.class);
        util.exportExcel(response, list, "员工请假数据");
    }

    /**
     * 获取员工请假详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:qj:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaStaffQjService.selectOaStaffQjById(id));
    }

    /**
     * 新增员工请假
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:qj:add')")
    @Log(title = "员工请假", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaStaffQj oaStaffQj)
    {
        return toAjax(oaStaffQjService.insertOaStaffQj(oaStaffQj));
    }

    /**
     * 修改员工请假
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:qj:edit')")
    @Log(title = "员工请假", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaStaffQj oaStaffQj)
    {

        return oaStaffQjService.updateOaStaffQj(oaStaffQj);
    }

    /**
     * 删除员工请假
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:qj:remove')")
    @Log(title = "员工请假", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaStaffQjService.deleteOaStaffQjByIds(ids));
    }
}
